package com.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping(value="/hello")
public class FirstController {
    @RequestMapping(value = "/firstController")
    public String handleRequest(HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {
        // 向模型对象中添加数据
        model.addAttribute("msg", "这是我的第2个 Spring MVC 程序");
        // 返回视图页面
        return "first";
    }
}
/*

public class FirstController implements Controller {
    @Override
    public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        // 创建 ModelAndView 对象
        ModelAndView mav = new ModelAndView();
        // 向模型对象中添加数据
        mav.addObject("msg","这是我的第一个 Spring MVC");
        // 设置逻辑视图名
        mav.setViewName("WEB-INF/jsp/first.jsp");
        // 返回 ModelAndView 对象
        return mav;
    }
}*/
